﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Core.Library
{
    public class DateTimeFunctions
    {
        public static string FormatDateVietNam(DateTime dt)
        {
            return string.Format("{0}-{1}-{2}", dt.Day, dt.Month, dt.Year);
        }

        public static string FormatTimeVietNam(DateTime dt)
        {
            return string.Format("{0}:{1}:{2}", dt.Hour, dt.Minute, dt.Second);
        }

        public static string ValidStrDateTime(string dt)
        {
            try
            {
                var isCheck = dt.Contains("/");
                var splitDateTime = dt.Split(isCheck ? '/' : '-');

                var validDateTime = string.Format("{0}/{1}/{2}", splitDateTime[2], splitDateTime[1], splitDateTime[0]);
                return validDateTime;
            }
            catch
            {
                return "";
            }            
        }

        public static DateTime ValidDateTime(string dt)
        {
            var isCheck = dt.Contains("/");
            var splitDateTime = dt.Split(isCheck ? '/' : '-');

            var validDateTime = string.Format("{0}/{1}/{2}", splitDateTime[2], splitDateTime[1], splitDateTime[0]);
            return ConvertUtility.ToDateTime(validDateTime);
        }

        public static DateTime ValidDateTime(string date, string hhmmsss)
        {
            var isCheck = date.Contains("/");
            var splitDateTime = date.Split(isCheck ? '/' : '-');

            var validDateTime = string.Format("{0}/{1}/{2} {3}", splitDateTime[2], splitDateTime[1], splitDateTime[0], hhmmsss);
            return ConvertUtility.ToDateTime(validDateTime);
        }
        public static string FormatIn_HHMM_DDMMYYYY(DateTime dt)
        {
            string sDay;
            string sMonth;
            string sHour;
            string sMin;

            if (dt.Hour < 10)
            {
                sHour = "0" + dt.Hour;
            }
            else
                sHour = dt.Hour.ToString();
            if (dt.Minute < 10)
            {
                sMin = "0" + dt.Minute;
            }
            else
                sMin = dt.Minute.ToString();
            if (dt.Month < 10)
            {
                sMonth = "0" + dt.Month;
            }
            else
                sMonth = dt.Month + "";
            if (dt.Day < 10)
            {
                sDay = "0" + dt.Day;
            }
            else
                sDay = dt.Day + "";

            return sHour + ":" + sMin + " - " + sDay + "/" + sMonth + "/" + dt.Year;
        }
        public static string FormatIn_DDMMYYYY(DateTime dt)
        {
            string sDay;
            string sMonth;
            string sHour;
            string sMin;

            if (dt.Hour < 10)
            {
                sHour = "0" + dt.Hour;
            }
            else
                sHour = dt.Hour.ToString();
            if (dt.Minute < 10)
            {
                sMin = "0" + dt.Minute;
            }
            else
                sMin = dt.Minute.ToString();
            if (dt.Month < 10)
            {
                sMonth = "0" + dt.Month;
            }
            else
                sMonth = dt.Month + "";
            if (dt.Day < 10)
            {
                sDay = "0" + dt.Day;
            }
            else
                sDay = dt.Day + "";

            return sDay + "/" + sMonth + "/" + dt.Year;
        }
    }
}